package com.dongbao.core.runable;

import com.dongbao.entity.AwardedInfo;
import com.dongbao.entity.CodeScoreInfo;
import com.dongbao.service.CodeGradeBiz;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.FilePath;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiUtilCore;

import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;

public class CodeInspectRunnable  implements Callable<CopyOnWriteArrayList<AwardedInfo>> {

    private VirtualFile file;

    private Module module;

    private CodeGradeBiz codeGradeBiz;

    private Project project;

    public CodeInspectRunnable(VirtualFile file, Module module, CodeGradeBiz codeGradeBiz,Project project){
        this.file = file;
        this.module = module;
        this.codeGradeBiz = codeGradeBiz;
        this.project = project;
    }

    @Override
    public CopyOnWriteArrayList<AwardedInfo> call() {
        CodeScoreInfo codeScoreInfo = new CodeScoreInfo();
        PsiFile psiFile = PsiUtilCore.getPsiFile(this.project, file);
        CodeScoreInfo calculate = codeGradeBiz.calculate(file,psiFile, codeScoreInfo,project);
        /* 分析评分并将错误原因弹出 */
        /* 遍历得分情况 进行分数的加减 */
        List<AwardedInfo> deductions = codeScoreInfo.getDeduction();
        return new CopyOnWriteArrayList<AwardedInfo>(deductions);
    }
}
